'''
Created on 11 jun 2011

@author: Yasin
'''

import os
import sys

from PyQt4 import QtCore, QtGui



class SystemTray(QtGui.QSystemTrayIcon):
    """ 
    class that the main application should use to spawn a system tray icon with a menu that has usefull actions...
    we don't provide the functionality here, the application should define and connect to the actions instead... 
    """
    
    def __init__(self, parent = None):
        
        super(SystemTray, self).__init__(parent)
        
        """ tray context menu """
        self._trayMenu        = QtGui.QMenu()
        self._preferencesMenu = QtGui.QMenu("Preferences")
        
        self.trayShow     = QtGui.QAction("Show",      self)
        self.trayHide     = QtGui.QAction("Hide",      self)
        self.traySync     = QtGui.QAction("Sync",      self)
        self.trayExit     = QtGui.QAction("Exit",      self)
        
        """ tray actions """
        self._trayMenu.addAction(self.trayShow)
        self._trayMenu.addAction(self.trayHide)
        self._trayMenu.addSeparator()
        self._trayMenu.addAction(self.traySync)
        self._trayMenu.addMenu(self._preferencesMenu)
        self._trayMenu.addSeparator()
        self._trayMenu.addAction(self.trayExit)
        
        """ set as drop down menu for rightclicking the systemtray icon """
        self.setContextMenu(self._trayMenu)
        
        """ tool tip """
        self.setToolTip("Stream-Doc Administrative tools")
        
        """ black icon """
        pixmap = QtGui.QPixmap(8, 8)
        pixmap.fill(QtCore.Qt.black)
        
        self.setIcon(QtGui.QIcon(pixmap))
        
        """ show system tray """
        self.setVisible(True)
        




if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    app.setStyle("plastique")

    tray = SystemTray()
    tray.show()
    
    sys.exit(app.exec_())